/**
 * Created by DukeCrushIt on 2015/8/27.
 */
class BuyDiamondItemRender extends eui.ItemRenderer{
    public constructor(){
        super();
        this.skinName = "pet.BuyDiamondItemSkin";
    }

    public onBuy(evt:egret.TouchEvent){
        SoundMgr.getInstance().playEffect(SoundMgr.BTN);
        if( Model.me.platform == PlatformEnum.WANBA){
            window["__charge"](this.data.id,1);
        }else if( Model.me.platform == PlatformEnum.QQBROWSER){
            window["qqbrowser_pay"](this.data.id,1);
        }
    }

    public lab_qty:eui.Label;
    public group_price:eui.Label;
    public img_buy:eui.Image;
    public img_star:eui.Image;
    public partAdded(name:string, instance:any){
        super.partAdded(name, instance);
        if(name == "lab_qty"){
            this.lab_qty = instance;
        }else if(name == "group_price"){
            this.group_price = instance;
        }else if(name == "img_buy"){
            this.img_buy = instance;
            this.img_buy.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBuy, this);
        }else if(name == "img_star"){
            this.img_star = instance;
            this.img_star.visible = Model.me.platform == PlatformEnum.WANBA;
        }
    }

    public dataChanged(){
        super.dataChanged();
        this.lab_qty.text = "x "+this.data.price;
        if( Model.me.platform == PlatformEnum.QQBROWSER){
            this.group_price.text = this.data.disPrice+"Q米";
        }else if( Model.me.platform == PlatformEnum.WANBA){
            this.group_price.text = Math.floor(this.data.disPrice*0.8).toString();
        }
        this.group_price.cacheAsBitmap = true;
    }
}